#6 Introduction to Python in VS Code
Faculty of Humanities and Social Sciences
University of Lucerne
28 March 2025
media a b c. \w \s [0-9] *.*enter the shiny world of Python 😎
get familiar with Visual Studio Code
| Name | What for? | Type | Examples |
|---|---|---|---|
| String | Text | str | "Hi!" |
| Integer, Float | Numbers | int, float | 20, 4.5 |
| Boolean | Truth values | bool | True, False |
| ⋮ | ⋮ | ⋮ | ⋮ |
| List | List of items (mutable) | list | ["Good", "afternoon", "everybody"] |
| Tuple | List of items (immutable) | tuple | (1, 2) |
| Dictionary | Relations of items (mutable) | dict | {"a":1, "b": 2, "c": 3} |
= vs. == contradicts the intuitiontab for autocompletion.ipynbFile > Open Folder.venvFile > New File > Jupyter NotebookThe output “Hello World!” should look like in the screenshot above.
git pull in your command-line.WSL: Ubuntu (blue badge in lower-left corner). If not, click on the badge and select New WSL Window.Follow the steps described on the slide Get started in VS Code.
Create a new file Jupyter Notebook with the following content, save it as hello_world.ipynb in the KED2025 folder. Then, run the code.
Does the output looks like the screenshot on the previous slide? If the execution doesn’t work as expected, ask me or your neighbour. There might be a technical issue.
When you are done already, you can experiment with the data types that we have discussed.
do something with each element of a collection
condition an action on variable content
function_name(arg1, ..., argn)print() len() sorted() ...def get_word_properties(word): # define function
"""
Print properties for a word and return its length.
"""
length = len(word)
sorted_letters = sorted(word, reverse=True)
print(f"{word} has {length} letters: {sorted_letters}".)
return length # optional return value
word_length = get_word_properties("computer") # call functionKED2025/ked/materials/code/python_basics.ipynbis a from the variable sentence using the right index.Write Python code that
Go to the next slide. Start with some of the great interactive exercises out there in the web.
Comments